package com.nbgroup.controller;

import com.nbgroup.mapper.ActivityMapper;
import com.nbgroup.mapper.CourseMapper;
import com.nbgroup.pojo.Contract;
import com.nbgroup.pojo.Course;
import com.nbgroup.pojo.common.PageResult;
import com.nbgroup.pojo.common.Result;
import com.nbgroup.pojo.dto.ContractDTO;
import com.nbgroup.service.ContractService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
public class ContractController {

    @Autowired
    private ContractService contractService;
    @Autowired
    private CourseMapper courseMapper;
    @Autowired
    private ActivityMapper activityMapper;

    /**
     *合同列表
     */
    @GetMapping("/contract/list")
    public PageResult query(ContractDTO dto){
        PageResult p=contractService.queryCon(dto);
        return p;
    }

    /**
     *添加合同
     */
    @PostMapping("/contract")
    public Result add(@RequestBody Contract contract){
        log.info("接收参数,{}",contract.getFileName());
        contractService.add(contract);
        return Result.success();
    }

    /**
     * 合同详情
     */
    @GetMapping("/contract/{id}")
    public Result detail(@PathVariable String id){
        Contract contract=contractService.getInfo(id);
        return Result.success(contract);
    }

    /**
     * 根据id查询合同信息
     */
    @GetMapping("/contract/detail/{id}")
    public Result getInfo(@PathVariable String id){
        Contract contract=contractService.getInfo(id);
        return Result.success(contract);
    }

    /**
     * 修改合同
     */
    @PutMapping("/contract")
    public Result update(@RequestBody Contract contract){
        contractService.update(contract);
        return Result.success();
    }

    /**
     * 预览
     */
    @GetMapping("{fileName}")
    public Result preview(@PathVariable String fileName){
        /*contractService.generateWord(fileName);*/
        return Result.success();
    }

    /**
     * 课程列表
     */
    @GetMapping("/clues/course/listselect")
    public Result courseList(){
        List<Course> courses = courseMapper.allCourse();
        return Result.success(courses);
    }

    /**
     *
     */
    @GetMapping("/system/notice/list/{id}")
    public Result getContract(@PathVariable Long id){
        return Result.success();
    }

    /**
     * 根据渠道查询活动
     */
    @GetMapping("/clues/activity/listselect/{channel}")
    public Result queryActivity(@PathVariable String channel){
        List<Course> courses = activityMapper.queryByChannel(channel);
        return Result.success(courses);
    }
}
